/**
 * Created by shidaiapp on 2017/9/29.
 */

import Vue from "vue";

/**
 * 初始化
 * @param self
 * @param tiyData
 */
export const init = (self, tiyData) => {
  tiyData.tPage.total = 1;
  tiyData.tPage.startIndex = 0;
  tiyData.tPage.stepNumber = 40;
  tiyData.tPage.currentPage = 1;
  tiyData.tParams.orderStartDate = "";
  tiyData.tParams.orderEndDate = "";
  tiyData.tParams.userName = '';
  self.$ySpliceAll(tiyData.tData.orderList);
};

/**
 * 从服务器请求列表
 * @param self
 * @param tiyData
 * @returns {Array}
 */
export const webList = (self, tiyData) => {
  self.$Spin.show();
  let data = {
    "pageSize": tiyData.tPage.stepNumber,
    "pageNum": tiyData.tPage.currentPage,
    "userName": tiyData.tParams.userName,
  };
  if(tiyData.tParams.orderStartDate){
    data.orderStartDate = Vue.prototype.$tiyQueryTime(new Date(tiyData.tParams.orderStartDate).getTime());
  }
  if(tiyData.tParams.orderEndDate){
    data.orderEndDate = Vue.prototype.$tiyQueryTime(new Date(tiyData.tParams.orderEndDate).getTime());
  }
  self.$apiOrder.firstOrders(data).then(function (response) {
    tiyData.tData.orderList.splice(0, tiyData.tData.orderList.length);
    self.$Spin.hide();
    if (response.success) {
      let orderPage = response.result;
      tiyData.tPage.total = orderPage.total;
      tiyData.tPage.stepNumber = orderPage.pageSize;
      orderPage.list.forEach(
        function (item) {
          tiyData.tData.orderList.push(item);
        }
      );
    } else {
      self.$Message.error(response.errorMessage);
    }
  });
};





